<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>新增OA知识点</title>
	<base href="<%=basePath%>"/>
	<link rel="stylesheet" type="text/css" href="css/common.css" />
	<link rel="stylesheet" href="<%=basePath%>/js/uploadify/css/uploadify.css" type="text/css"></link>
    <link type="text/css" href="js/mcdropdown/css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
    <script type="text/javascript" src="js/mcdropdown/lib/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/mcdropdown/lib/jquery.mcdropdown.js"></script>
    <script type="text/javascript" src="js/mcdropdown/lib/jquery.bgiframe.js"></script>
    <script type="text/javascript" src="<%=basePath%>/js/uploadify/jquery.uploadify-3.1.min.js"></script>
    <script language="JavaScript" type="text/javascript" src="<%=basePath%>js/my97/WdatePicker.js" defer="defer"></script>
	<style type="text/css"> 
	  fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
	  form label {font-weight:bold;}
	  table{margin:10px 10px};
	  td{line-height: 40px;}
	  input[type="text"]{width:300px;}
	  input[type="password"]{width:250px;}
	  input[type="textarea"]{width:250px;}
	</style>
	<script type="text/javascript">
   	  $(document).ready(function(){
  	  	  $.ajaxSetup ({ cache:false,async: false });
	      var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
	      $("#itemForm").submit(function(){
	    	  $("#btn_insert").attr("disabled","disabled");
	          $(this).ajaxSubmit(options);
	          return false;
	      }); 

		  //文件上传组件
		  $("#file_upload").uploadify({   
	          'height'        : 27,    
		      'width'         : 80,     
		      'buttonText'    : '添加附件',   
		      'removeCompleted': false,         //上传完毕上传列表是否去除 
	          'fileSizeLimit': '50MB',          //上传文件大小设置 单位可以是B、KB、MB、GB 
	          'swf'           : '<%=basePath%>/js/uploadify/uploadify.swf',   
	          'uploader'      : '<%=basePath%>req/oarepository/upload.do',   
		      'auto'          : false,   
		      'formData'      : {'reqId':''},  
		      'fileTypeExts'  : '*.*',   
		      'onUploadStart' : function(file) {   
		           $("#file_upload").uploadify("settings","formData", {'reqId':reqId});   
		           },   
		      'onUploadSuccess':function(file, data, response){ 
		           $('#' + file.id).find('.data').html(' 上传完毕');
		           },   
		      'onUploadComplete':function(file){   
			       $('#importLispDialog').window('close');   
		           }   
		      });          
  		});
  
	  function beforeSubmit() {
		  if(isEmpty($("#title").val())) { $('#error_label').text("错误信息：标题不能为空！"); 
		  	$("#p_error").show();
		  	$("#btn_insert").removeAttr("disabled");
	    	return false; }
		  if(isEmpty($("#content").val())) { $('#error_label').text("错误信息：内容不能为空！"); 
		  	$("#p_error").show();
		  	$("#btn_insert").removeAttr("disabled");
	  		return false; }
		  if(isEmpty($("#problem").val())) { $('#error_label').text("错误信息：问题描述不能为空！"); 
		  	$("#p_error").show();
		  	$("#btn_insert").removeAttr("disabled");
	  		return false; }
		  if(!validateSize($("#title").val(), 0, 100)){
			  $('#error_label').text("错误信息：标题长度必须在0~100位之间，或者小于50个汉字！"); 
			  $("#p_error").show();
			  $("#btn_insert").removeAttr("disabled");
			  return false;
		  }
	      return true;
	  }

    function process(responseJson) {
      $("#btn_insert").removeAttr("disabled");
      if(responseJson.code == 0) {
          $('#error_label').text("错误信息：" + responseJson.message);
          $("#p_error").show();
          return;
      }
      else{
    	 $("#reqId").val(responseJson.reqId);
	   	 if(confirm('添加成功是否上传附件?'))
       	 {
	       	 $("#title").attr('disabled','true');
	    	 $("#content").attr('disabled','true');
	    	 $("#problem").attr('disabled','true');
	    	 $("#btn_insert").attr('disabled','true');
       	 }else
       	 {
       		var qs = $("#qs").val();
            location.href = "<%=basePath%>req/oarepository/list.do?" + qs;
       	 }
      }
    }  

    function startUpload(){   
    	reqId = $("#reqId").val();
		if(reqId.replace(/\s/g,'') == '')
		{
			alert("请先提交基本信息后再上传附件！");   
        	return false;    
		}else
	    {
		    $('#file_upload').uploadify('upload','*');   
	    } 
	 }   
</script>
</head>
<body>
  <div>
    <fieldset>
      <legend>新增OA知识：</legend>
      <form id="itemForm" method="post" action="req/oarepository/insert.do">
        <input id="qs" name="qs" type="hidden" value="${qs}"/>
      	<p id = "p_error" style = "margin:10px 10px;">
      	    <label id="error_label" style="color:red;"></label>
      	</p>
        <table>
          <tr>
          	<td><input type="hidden" name="reqId" id="reqId"></td>
          </tr>
          <tr>
            <td><label for="title">标题：</label></td>
            <td>
            	<input type="text" name="title" id="title" value="${item.title }"/>
            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
            	<label for="title">0～100位</label>
            </td>
          </tr> 
          <tr>
            <td valign="top"><label for="content">内容：</label></td>
            <td valign="top"><textarea name="content" id="content" cols="50" rows="10"><c:out value="${item.content }"/></textarea>
            <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
          </tr>       
          <tr>
            <td valign="top"><label for="problem">问题描述：</label></td>
            <td valign="top"><textarea name="problem" id="problem" cols="50" rows="10"><c:out value="${item.problem }"/></textarea>
            <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
          </tr>   
          <tr>
            <td valign="top"><label for="result">备注信息：</label></td>
            <td valign="top"><textarea name="remark" id="remark" cols="50" rows="10"><c:out value="${item.remark }"/></textarea>
          </tr>              
          <tr>
            <td></td>
            <td>
            	<input type="submit" id="btn_insert" value="提交" style="width:80px;" />
            	<input type="button" id="btn_back" value="返回" onclick="history.back();" style="width:80px;" />
            </td>
          </tr>
        </table>
      </form>
    </fieldset>
  </div>
  
  <div id="uploadDiv" style="float:left;">
		<fieldset>
		   <legend>上传附件：</legend>
		   <input type="file" name="uploadify" id="file_upload" />   
		   <hr>   
           <a onclick="startUpload();" href="javascript:void(0);">开始上传</a>    
           <a href="javascript:$('#file_upload').uploadify('cancel', '*')" >取消所有上传</a>   
        </fieldset>
    </div>
</body>
</html>